package com.neusoft.a132wxyorderingdish.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.neusoft.a132wxyorderingdish.R;
import com.neusoft.a132wxyorderingdish.beans.CommentBean;

import java.util.List;

public class FoodInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<CommentBean> commentBeans;
    private LayoutInflater layoutInflater;

    public FoodInfoAdapter(Context context, List <CommentBean> commentBeans, int foodinfo_item){
        this.context=context;
        this.commentBeans=commentBeans;
        layoutInflater=LayoutInflater.from(context);
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v=layoutInflater.from(viewGroup.getContext()).inflate(R.layout.foodinfo_item,viewGroup,false);
        FoodInfoViewHolder holder=new FoodInfoViewHolder(v);
        return holder;

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        final CommentBean commentBean=commentBeans.get(position);
        if(null==commentBean)
            return;

        FoodInfoViewHolder foodInfoViewHolder=(FoodInfoViewHolder)viewHolder;
        foodInfoViewHolder.tv.setText(commentBean.getUsername());
        foodInfoViewHolder.tv1.setText(commentBean.getContent());
        foodInfoViewHolder.tv2.setText(commentBean.getComment_time());

    }

    @Override
    public int getItemCount() {
        if (commentBeans == null){

            return 0;
        }
        return commentBeans.size();

    }

    public class FoodInfoViewHolder extends RecyclerView.ViewHolder{
        public View view;
        public TextView tv,tv1,tv2;

        public FoodInfoViewHolder(View view) {
            super(view);
            tv2=view.findViewById(R.id.foodinfo_username);
            tv=view.findViewById(R.id.foodinfo_content);
            tv1=view.findViewById(R.id.foodinfo_comment_time);

        }
    }

}
